// game/collision.go

package game

func (s *Snake) CollidesWithf(f *Food) bool {
	// 检测蛇头是否与食物碰撞
	head := s.segments[0]
	if head.x == f.x && head.y == f.y {
		s.Eat()
		return true
	}
	return false
}
func (s *Snake) CollidesWithItself() bool {
	// 检测蛇是否与自身碰撞
	head := s.segments[0]
	for i := 1; i < len(s.segments); i++ {
		if head.x == s.segments[i].x && head.y == s.segments[i].y {
			return true
		}
	}
	return false
}
func (s *Snake) CollidesWithBorder(screenWidth, screenHeight int) bool {
	// 检测蛇是否与边界碰撞
	head := s.segments[0]
	if head.x < 1 || head.x >= screenWidth/gridSize-1 || head.y < 1 || head.y >= screenHeight/gridSize-1 {
		return true
	}
	return false
}
